<!DOCTYPE html>
<html>
<head>
<div th:include="base-libs :: base-libs" />
<title>床位设置</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<style>
	.laydate-icon{
		width:87% !important;
		padding-left: 5px;
		line-height: 28px;
		background-color: #fff;
		height: 28px;
		border: 1px solid #B6B6B6;
		border-radius: 5px;
	}
	.spanBtn{
		font-weight: bold;
    	color: blue;
    	cursor:pointer;
	}
</style>

<script th:inline="javascript">
	/**读取request中的初始化数据*/
	var requestData = [[${requestData}]];
</script>
<script>
	$(function(){
		$(this).registerManagerPage();
    	initView();
    	initData();
    })
    
    function initData(){
        //根据权限，隐藏不能使用的查询条件
        if(!requestData["isManager"]){
            var value = {PTJGID: parent.userInfo.PTJGID,YLJGMC: parent.userInfo.YLJGMC};
            $("#combogridYljg").combogrid("setValue", value);
            $(".hidden").hide();
        }
		$("#btnQuery").trigger("click");
	}
    	
    function initView() {
    	//回车查询
     	enterToQuery(btnQueryHandler);

        /** 医疗机构combogrid */
        var readonly = !requestData["isManager"];
    	$("#combogridYljg").combogrid({
            height: 30
            ,width: 300
            ,panelWidth: 500
            ,singleSelect: true
            ,pagination: true
            ,idField: 'PTJGID'
            ,textField: 'YLJGMC'
            ,mode: "remote"
            ,readonly: readonly
            ,hasDownArrow: !readonly
            ,url: "/console/yljgxx/queryPageSummary.service"
            ,delay: 1000
            ,reversed: false
            ,fitColumns: true
            ,columns:[[
                {field:'YLJGMC',title:'机构名称',width:240},
                {field:'XZQHMC',title:'行政区划',width:80},
                {field:'WSJGLBMC',title:'机构类别',width:90},
                {field:'YYDJMC',title:'机构等级',width:80}
            ]]
            ,onBeforeLoad: function(queryParams) {
                var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
                if (url) {
                    queryParams["pageSize"] = queryParams["rows"];
                    queryParams["pageNumber"] = queryParams["page"];
                    queryParams["YLJGMC"] = queryParams["q"];
                    return true;
                }else{
                    return false;
                }
            },
            onClickRow : function(rowIndex, rowData){
    			$("#PTJGID").val(rowData.PTJGID);
            },
            onLoadSuccess : function(data){

			}
        });
		
		//点击input展开combogrid
		$(".validatebox-text").click(function(){
			$('.combo-arrow').trigger('click');
		})
		
		$("#qyhzTable").datagrid({
				idField : "GZBH",
				striped : true,
				clickToSelect: true,
				fitColumns: true,
				fit:true,
				scrollbarSize:15,
				singleSelect: true,
				columns : [[
// 						{field : "xz",checkbox:true},
						{field : "YLJGMC",title : "医疗机构名称",width:80, align:'center'},
						{field : "FHSJ",title : "放号时间",width:50, align:'center'},
						{field : "FHQJ",title : "放号区间",width:50, align:'center'},
						{field : "SFBHDT",title : "是否包含当天",width:60, align:'center', formatter:function(value){
							var sfbhdtObj = {'0':'否','1':'是'};
							return sfbhdtObj[value] || value;
						}},
						{field : "ZT",title : "是否启用",width:50, align:'center', formatter:function(value){
							var ztObj = {'1':'启用','2':'停用','3':'作废'};
							return ztObj[value] || value;
						}},
						{field : "CZ",title : "操作",width:60, align:'center', formatter:function(value,row){
							var rowCopy = JSON.stringify(row).replace(/"/g, '&quot;');
							var xg = '<span class="spanBtn" onclick="toAddView('+ rowCopy +')">修改</span>';
							var sc = '<span class="spanBtn" onclick="deleteCwsz('+ rowCopy +')">删除</span>';
							var ty = '<span class="spanBtn" onclick="freezeCwsz('+ rowCopy +',2)">停用</span>';
                            var qy = '<span class="spanBtn" onclick="freezeCwsz('+ rowCopy +',1)">启用</span>';
							if(row.ZT == 1){
								return ty + "&nbsp;&nbsp" + xg + "&nbsp;&nbsp" + sc;
							}
							if(row.ZT == 2){
                                return qy + "&nbsp;&nbsp" + xg + "&nbsp;&nbsp" + sc;
							}
						}}
				]],
				pagination : true,
				pageList: [10, 20, 50, 100, 200],
				method : "post",
				onBeforeLoad : function(params) {
					params.PTJGID = $("#combogridYljg").combobox("getValue");
					getContainerDataByClassName('conditionBox','condition',params);//查询条件
				},
				onLoadSuccess: function(data){
// 					alert(JSON.stringify(data))
 				},
		});
		
	}

    	
   	/** 查询  */
   	function btnQueryHandler(){
   		$("#qyhzTable").datagrid({"url": "queryPage.service"});
   	}
   	
   	/** 跳转到新增页面  */
   	function toAddView(row){
   	    if($.isEmptyObject(row) && !requestData["isManager"] && $("#qyhzTable").datagrid('getRows').length>0){
   	        if($("#qyhzTable").datagrid('getRows')[0].ZT == 1){
				$.QuickAlert.alertFail({content: '您已拥有放号规则设置！'});
				return;
			}
		}
   		StoreCache.setCache('fhgzszData',row);
   		$.QuickUrlUtils.redirectUrl("manager.html");
   	}
   	
   	/** 删除床位设置  */
   	function deleteCwsz(row){
   		$.QuickAlert.alertConfirm({
			content : "删除后不可恢复，是否继续？",
			callback : function() {
				$.QuickRemote.AjaxJson("save", deleteHandler, {type: 'update',GZBH: row.GZBH, ZT: 3});
			}
		})
   	}
   	
   	/** 停用/启用 床位设置  */
   	function freezeCwsz(row,ZT){
        var ztObj = {'1':'启用','2':'停用'};
   	    $.QuickAlert.alertConfirm({
   	        content : "确认"+ztObj[ZT]+"该规则？",
   	        callback : function() {
				$.QuickRemote.AjaxJson("save", deleteHandler, {type: 'update',GZBH: row.GZBH, ZT: ZT},ZT);
   	        }
   	    })
   	}
   	
   	/** 删除回调 */
	function deleteHandler(result,ZT){
		if(result.state){
		    var tip = result.info;
		    if(ZT==1) tip = '您已启用该规则！';
			if(ZT==2) tip = '您已停用该规则！';
			$.QuickAlert.alertNormal(tip, {callback: function(){
				$("#btnQuery").trigger("click");
			}});
		}else{
			$.QuickAlert.alertFail({content: result.info});
		}
	}
</script>

</head>

<body>
	<div class="easyui-layout" fit="true" border="false">
		<div region="north" style="overflow:hidden;padding:15px 0px;padding-left:15px;background:#f9f9f9" border="false">
			<table id="conditionBox">
				<tr>
					<td class="query-text hidden">医疗机构名称：</td>
					<td class="query-content hidden">
						<input id="combogridYljg" />
					</td>
					<td class="query-text" style="width: 170px;text-align:left">
						<button id="btnQuery" class="btn btn-info hidden" type="button" onclick="btnQueryHandler()">查询</button>
						<button type="button" onclick="toAddView()" style="margin-left:15px;">新增</button>
					</td>
				</tr>
			</table>
		</div>
		<div region="center" border="false">
			<table id="qyhzTable" border="false"></table>
		</div>
	</div>
	
</body>
</html>
